package com.gitee.wsl.transform.encode

import com.gitee.wsl.transform.encode.unicode.Unicode
import kotlin.test.Test
import kotlin.test.assertEquals


/**
 * Unicode 单元测试
 *
 * @author looly
 */
class UnicodeTest {
    @Test
    fun convertTest() {
        val s = Unicode.toUnicode("aaa123中文", true)
        assertEquals("aaa123\\u4e2d\\u6587", s)

        val s1 = Unicode.toString(s)
        assertEquals("aaa123中文", s1)
    }

    @Test
    fun convertTest2() {
        val str = "aaaa\\u0026bbbb\\u0026cccc"
        val unicode = Unicode.toString(str)
        assertEquals("aaaa&bbbb&cccc", unicode)
    }

    @Test
    fun convertTest3() {
        val str = "aaa\\u111"
        val res = Unicode.toString(str)
        assertEquals("aaa\\u111", res)
    }

    @Test
    fun convertTest4() {
        val str = "aaa\\U4e2d\\u6587\\u111\\urtyu\\u0026"
        val res = Unicode.toString(str)
        assertEquals("aaa中文\\u111\\urtyu&", res)
    }

    @Test
    fun convertTest5() {
        val str =
            "{\"code\":403,\"enmsg\":\"Product not found\",\"cnmsg\":\"\\u4ea7\\u54c1\\u4e0d\\u5b58\\u5728\\uff0c\\u6216\\u5df2\\u5220\\u9664\",\"data\":null}"
        val res = Unicode.toString(str)
        assertEquals(
            "{\"code\":403,\"enmsg\":\"Product not found\",\"cnmsg\":\"产品不存在，或已删除\",\"data\":null}",
            res
        )
    }

    @Test
    fun issueI50MI6Test() {
        val s = Unicode.toUnicode("烟", true)
        assertEquals("\\u70df", s)
    }
}